TidyTuesday - Star Wars Survey

This weeks dataset contains survey results on the popularity of the Star Wars films and characters in 2014. The results are described in a news article by fivethirtyeight https://fivethirtyeight.com/features/americas-favorite-star-wars-movies-and-least-favorite-characters/. There were 1,186 respondants to the survey. The dataset is very untidy!

starwars <- read_csv('starwars.csv', col_names = TRUE)
#Extract movie names and character names from the data
movie_titles <- read_lines('starwars.csv') %>% str_split(",") %>% {.[[3]][4:9]}
movie_char<- read_lines('starwars.csv') %>% str_split(",") %>% {.[[2]][16:29]}

The following code tidies the dataset:

starwars_tidy <- starwars %>% mutate(seen_films = rowSums(!is.na(.[4:9]))) %>% filter(`Have you seen any of the 6 films in the Star Wars franchise?`=="Yes", seen_films==6) %>% rename_at(vars(`Please rank the Star Wars films in order of preference with 1 being your favorite film in the franchise and 6 being your least favorite film.`:X15), funs(paste(movie_titles))) %>% rename_at(vars(`Please state whether you view the following characters favorably, unfavorably, or are unfamiliar with him/her.`:X29), funs(paste(movie_char)))